<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    span{
        color: #ff6700;
        font-size: 16px;
        font-family: "宋体";
    }
</style>
<body>
<form action="http://www.baidu.com" onsubmit="return checkAll()">
    账号:<input type="text" id="name"><span id="name-info"></span>
    <br><br>
    密码:<input type="password" id="pwd"><span id="pwd-info"></span>
    <br><br>
    <input type="submit">
</form>
</body>
</html>
<script type="text/javascript">
    function checkAll() {
        var na = checkName();
        var pd = checkPwd();
        if (na && pd) {
            return true
        } else {
            return false
        }
    }
        function checkName() {
            // 6-8数字和字母组成
            var reg = /^[a-zA-Z0-9]{6,8}$/
            if (reg.test(document.getElementById("name").value)) {
                document.getElementById("name-info").innerHTML = "";
                return true
            } else {
                document.getElementById("name-info").innerHTML = "账号是由6到8位数字或字母组成";
                return false
            }
        }

        function checkPwd() {
            //6位数字和字母组成
            var reg = /^[0-9]{6}$/
            if(reg.test(document.getElementById("pwd").value)){
                document.getElementById("pwd-info").innerHTML = "";
                return true
            }else {
                document.getElementById("pwd-info").innerHTML = "账号是由6位数字组成";
                return false
            }
        }



</script>